<?php
/*
 * article class
 */
namespace lightblog\admin\controller;

use lightblog\engine\controller;
use lightblog\admin\controller\adminController;
use lightblog\admin\model\articleModel;

class article extends adminController {
    function newArticleAction() {
        if (\lightblog::$app->request->method == 'POST') {
            if ($this->addNewArticle()) {
                header('location: ' . route('index', 'index'));
            }
        }

        $model = new articleModel();
        $category = $model->getCategory();
        $tags = $model->getTags();

        $data['category'] = $category;
        $data['tags'] = $tags;

        return $this->render($data);
    }

    function addNewArticle() {
        $post = \lightblog::$app->request->parameter->post;

        $model = new articleModel();
        $model->title = $post['title'];
        $model->content = $post['content'];
        $model->category = $post['category'];
        $model->tags = $post['tags'];

        return $model->addNewArticle();
    }

}
